package com.turing.data.scripts.contract.filter


import com.turing.common.util.FileUtils
import com.turing.data.engine.utils.ScriptsUtils
import com.turing.data.vo.out.review.DependParamsVO
import com.turing.data.vo.out.review.TaskElementVO

class MinSubscribe_30177_10_filter {

    static List< TaskElementVO.DrawResultVO > doConvert(DependParamsVO dependParams){

        def Regex_1 = /.*\d.*/
        def Regex_2 = /.*认购*/
        def Regex_3 = /.*申购.*/

        List< TaskElementVO.DrawResultVO > trueValueSet = new ArrayList<>()
        def set = new HashSet()
        List<TaskElementVO.DrawResultVO > resultVOs = ScriptsUtils.tryInitResult(dependParams)
        if (resultVOs!=null && resultVOs.size()>0) {
            for (int i = 0; i < resultVOs.size(); i++) {
                def drawResultVO = resultVOs.get(i)
                def childTaskSn = drawResultVO.childTaskSn
                if(null == childTaskSn || childTaskSn == ""){
//                    return  resultVOs
                    continue
                }
                def start = drawResultVO.start
                def end = drawResultVO.end
                def text = drawResultVO.text
                text = text.replaceAll("\n","")
                def textPathMap = dependParams.textPathMap
                def rawPath = textPathMap.get(drawResultVO.childTaskSn)
                def rawText = FileUtils.loadJson(rawPath)
                def expandOffset = 0
                while( expandOffset < 10 && start > expandOffset ){
                    def expandString = rawText.substring(start-expandOffset,end)
                    if( (expandString =~ Regex_3 ||  expandString =~ Regex_2) && text =~  Regex_1 ){
                        trueValueSet.add(drawResultVO)
                        set.add(drawResultVO.text)
                        return trueValueSet
                    }
                    expandOffset ++
                }
            }
        }

        TaskElementVO.DrawResultVO defaultDrawResultVO = new TaskElementVO.DrawResultVO()
        defaultDrawResultVO.text = ""
        trueValueSet.add(defaultDrawResultVO)
        return  trueValueSet

    }

}
